home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Games Collection 1 / software vault.zip / software vault / CDR10 / SPX20.ZIP / SPX_DOC.ZIP / SPX_EMS.DOC < prev    next >
Text File  |  1993-09-27  |  4KB  |  106 lines

  1. { SPX Library Version 2.0  Copyright 1993 Scott D. Ramsay }
  2.  
  3.  SPX_EMS is a simple expanded memory unit.  It calls only the basic expanded
  4. memory manager interrupt functions.
  5.  
  6.  Expanded memory is accessed through a 64k window.  When you want to
  7. access or place data in expanded memory, the at least 16k of the window
  8. must be mapped "point" to its location.  Once the window is mapped, you can
  9. place or read data from the window location and the memory managager
  10. automatically does the transfer.
  11.  
  12. ───────────────────────────────────────────────────────────────────────────
  13. function emsINSTALLED:boolean;
  14.  
  15.    Returns TRUE if expanded memory is installed.
  16. ───────────────────────────────────────────────────────────────────────────
  17. procedure emsVERSION(var st:string);
  18.  
  19.    Returns the expanded memory version string
  20.  
  21.    st      String name of the memory version
  22. ───────────────────────────────────────────────────────────────────────────
  23. function emsSTATUS:boolean;
  24.  
  25.    Returns TRUE if expanded memory is ok.
  26. ───────────────────────────────────────────────────────────────────────────
  27. procedure emsPAGES(var totalpages,pagesavailable:word);
  28.  
  29.    Gets the number of 16k pages of expanded memory you have and how
  30.  many are free.
  31.  
  32.     totalpages        Number of 16k pages are free
  33.     pagesavailable    Number of pages available
  34. ───────────────────────────────────────────────────────────────────────────
  35. procedure emsADDRESS(var address:word);
  36.  
  37.    Get the segment address of the 64k window.
  38.  
  39.    address   segment address of the 64k window
  40.  
  41.    The offset of the 64k window always ranges from 0 to $FFFF (64k) ;)
  42. ───────────────────────────────────────────────────────────────────────────
  43. procedure emsGETMEM(pagesneeded:word;var handle:word);
  44.  
  45.   Allocates expanded memory.  Retuns a handle value to the allocated area.
  46.  
  47.   pagesneeded   The number of 16k pages to allocate
  48.   handle        The handle to the number of pages.
  49. ───────────────────────────────────────────────────────────────────────────
  50. procedure emsFREEMEM(handle:word);
  51.  
  52.   Deallocates expanded memory.  All allocated memory must be deallocated
  53.   after use or program end.  Expanded memory is not automatically deallocated
  54.   at program exit.
  55. ───────────────────────────────────────────────────────────────────────────
  56. procedure emsMAP(handle,logicalpage,physicalpage:word);
  57.  
  58.   Map expanded memory to the 64k window.
  59.  
  60.   handle        Handle to the allocated memory to map
  61.   logicalpage   Logical page of the memory.  Always (0..n)
  62.                 where n = number_of_pages_allocated - 1;
  63.   physicalpage  Physical page of the window. Always (0..3)
  64.                 where 0..3 specifies the 16k region of the
  65.                 window.
  66. ───────────────────────────────────────────────────────────────────────────
  67.     uses spx_ems;
  68.  
  69.     var
  70.       segment,           { 64k window address }
  71.       handle,            { allocated handle }
  72.       tp,pa,             { total pages, pages available }
  73.       na    : word;      { number of pages to allocate }
  74.       d     : integer;   { counter }
  75.       s     : string;    { test data }
  76.     begin
  77.       if not emsINSTALLED               { check for expanded memory }
  78.         then
  79.           begin
  80.             writeln('No expanded memory');
  81.             halt;
  82.           end;
  83.       emsADDRESS(segment);              { get window segment }
  84.       emsPAGES(tp,pa);                  { get expanded size }
  85.       writeln('expanded memory');
  86.       writeln('   Total : ',longint(tp)*$FFFF,' bytes');
  87.       writeln('   Free  : ',longint(pa)*$FFFF,' bytes');
  88.       if pa=0
  89.         then
  90.           begin
  91.             writeln('You have no expanded memory free');
  92.             halt;
  93.           end;
  94.       na := 4; { Allocate 64k byte }
  95.       if na>pa
  96.         then na := pa; { make sure we only allocate up to what is available }
  97.       emsGETMEM(handle,na);  { allocate some memory }
  98.       emsMAP(handle,0,0);    { map 16k of ems memory to 1st 16k of window }
  99.       s := 'This is a test';            { test data }
  100.       move(s,mem[segment:0],sizeof(s)); { move string to 1st 16k in window }
  101.       s := '';                          { clear S }
  102.       move(mem[segment:0],s,sizeof(s));  { move ems memory to S }
  103.       writeln(s);
  104.       emsFREEMEM(handle);    { deallocate expanded memory }
  105.     end.
  106.